home *** CD-ROM | disk | FTP | other *** search
Text File | 2000-09-28 | 5.2 KB | 157 lines | [TEXT/CWIE] |
- /*
-
- File: StandardGetAlias.c
-
- Contains: Routines needed to use CustomGetFile for selecting alias
- files, rather than the original item the alias points to.
-
- Copyright: © 1998-1999 by Apple Computer, Inc., all rights reserved
-
- Technology: Standard File dialogs
-
- Version: 1.0
-
- Bugs?: For bug reports, consult the following page on
- the World Wide Web:
-
- http://developer.apple.com/bugreporter/
-
- ========================================================================
- You may incorporate this sample code into your applications without
- restriction, though the sample code has been provided “AS IS” and the
- responsibility for its operation is 100% yours. However, what you are
- not permitted to do is to redistribute the source as “DSC Sample Code”
- after having made changes. If you’re going to re-distribute the source,
- we require that you make it clear in the source that the code was
- descended from Apple Sample Code, but that you’ve made changes.
- ========================================================================
-
- A Few Notes:
-
- The routines in this file have been tested, though not exhaustively so.
- They should not be used as the basis of the final code you use in your
- application without further testing.
-
- The error reporting is fairly complete, but there could be errors encounter
- which deserve a more descriptive message than is displayed here.
-
- This code assumes the presence of System 7 or later. You should check
- the system version before using these routines in your code.
-
- This routine uses CustomGetFile dialog, supplying custom filter and hook functions.
-
- The MoreFiles package is used for some of the sanity checking in the routines,
- and is not included with this project. You will need to obtain the
- MoreFiles package (from the developer ftp site) to build an use this project.
-
- Andy Bachorski - Apple Developer Technical Support (DTS)
-
- Writers:
-
- (afb) Andy Bachorski
-
- Change History (most recent first):
-
- <1> 2/9/99 afb first checked in
-
- */
-
- //****************** Universal Interfaces ****************************
-
- #include <Aliases.h>
- #include <Controls.h>
- #include <Folders.h>
- #include <Scrap.h>
- #include <StandardFile.h>
- #include <TextUtils.h>
- #include <ToolUtils.h>
-
- // #include "MoreFilesExtras.h"
-
-
- //****************** Project Interfaces ****************************
-
- #include "StandardGetAlias.h"
-
-
- //****************** Private Definitions ****************************
-
- enum {
- kFilterAllTypes = -1, // pass all types to filter proc in StandardFild get dialog
- kUseStandardDialog = 0
- };
-
-
- //****************** Private Prototypes ****************************
-
- pascal Boolean OnlyAliasFilesSFFilter( CInfoPBPtr myCInfoPBPtr, Ptr dataPtr );
- pascal short SFGetFolderDialogHook( short item, DialogPtr dialogPtr, Ptr dataPtr );
-
-
- //******************************************************************************
- //
- // This routine assumes the presence of CustomGetFile, which is available in
- // System 7 and later. You should check for the right system version before
- // calling this routine.
- //
- pascal void StandardGetAlias( StandardFileReply *sfReplyPtr )
- {
- Point dialogTopLeft = { -1, -1 }; // Use to center the dialog.
- SFTypeList mySFTypeList = { 0 };
-
- FileFilterYDUPP fileFilterUpp = NewFileFilterYDProc( OnlyAliasFilesSFFilter );
- DlgHookYDUPP dialogHookUPP = NewDlgHookYDProc( SFGetFolderDialogHook );
-
- // Then display the custom choose folder dialog.
-
- CustomGetFile( fileFilterUpp, kFilterAllTypes, mySFTypeList, sfReplyPtr, kUseStandardDialog,
- dialogTopLeft, dialogHookUPP, nil, nil, nil, nil );
-
- DisposeRoutineDescriptor( dialogHookUPP );
- DisposeRoutineDescriptor( OnlyAliasFilesSFFilter );
-
- return;
- }//end StandardGetAlias
-
- //******************************************************************************
- //
- // Return false (to display the item) if the item is a folder or alias file.
- //
- pascal Boolean OnlyAliasFilesSFFilter( CInfoPBPtr myCInfoPBPtr, Ptr dataPtr )
- {
- #pragma unused ( dataPtr )
-
- Boolean isAlias = ( myCInfoPBPtr->hFileInfo.ioFlFndrInfo.fdFlags & kIsAlias ) != 0;
- Boolean isFolder = ( myCInfoPBPtr->hFileInfo.ioFlAttrib & ioDirMask ) != 0;
-
- // Because the semantics of the filter proc are "true means don't show
- // it" the combined flags must be inverted before being returned.
-
- return !( isAlias || isFolder );
- }//end OnlyAliasFilesSFFilter
-
- //******************************************************************************
-
- pascal short SFGetFolderDialogHook( short dialogItem, DialogPtr dialogPtr, Ptr dataPtr )
- {
- #pragma unused ( dataPtr )
-
- // Sanity check first. Be sure it's really a CustomGetFile dialog.
-
- if ( ((WindowPeek)dialogPtr)->refCon == sfMainDialogRefCon )
- {
- // sfHookOpenAlias is the only dialog item of interest.
- // To convince CustomGetFile to return the FSSpec for the alias file,
- // rather than its target item, simply return sfItemOpenButton as the
- // dialog item.
- if ( dialogItem == sfHookOpenAlias )
- {
- dialogItem = sfItemOpenButton;
- }
- }
-
- return dialogItem;
- }//end SFGetFolderDialogHook
-
- //******************************************************************************
-